3D Graphics Programming with QuickDraw 3D 1.5.4
Previous | QD3D Book | Overview | Chapter Contents | Next |
For some modeling operations--in particular, applying a texture to the surface of an object--QuickDraw 3D needs to perform a mapping between the texture and the surface. This mapping is usually specified using a pair of uv parametric spaces, one defined over the texture and one defined over the surface of the object. A uv parametric space is also called a parameterization. A uv parametric space applied to the surface of an object is a surface parameterization.
A texture is typically specified as a pixmap, that is, as a rectangular array of pixels. In that case, the texture has a simple uv parameterization (shown in Figure 8 ) that allows QuickDraw 3D to select pixels in the pixmap by varying u and v in the range 0 to 1. Figure 8 shows the pixmap, with its origin in the upper-left corner; it also shows the standard pixmap parameterization, which maps the unit box from 0.0 to 1.0 along the u and v axes.
Figure 8 The standard uv parameterization for a pixmap
In addition to this texture parameterization, QuickDraw 3D uses another parameterization that picks out points on the surface of the object. For texture mapping, the most useful standard surface parameterization is any parameterization that results in the entire texture being mapped to the entire surface exactly once. QuickDraw 3D defines a standard surface parameterization for most of the primitive QuickDraw 3D geometric objects. In some cases, an object's standard surface parameterization is obtained from the object's natural surface parameterization (that is, a parameterization that defines the surface). For example, a NURB patch is naturally parameterized by its u and v knot vectors. (However, note that a texture will be mapped only into the subregion of the patch that corresponds to the 1 by 1 subregion of domain space. You must take this into account when assigning values larger than 1 to a patch's knot vectors.)
In other cases, however, there is no natural surface parameterization for an object, and QuickDraw 3D must define an arbitrary standard surface parameterization for it. For example, for a box, which has no natural surface parameterization, QuickDraw 3D uses the standard surface parameterization shown in Figure 9 .
Figure 9 The standard surface parameterization of a box
Figure 10 shows the result of mapping the texture shown in Figure 8 onto the front face of a box.
Figure 10 A texture mapped onto a box
Similarly, an ellipsoid has the standard surface parameterization shown in Figure 11 .
In this case, the v parameter varies from 0 to 1 as it sweeps from the end of the orientation vector to the top of the ellipsoid, and the u parameter varies from 0 to 1 as it sweeps around in the plane defined by the major radius and minor radius. In the coordinate system defined by the orientation, the major axis, and the minor axis, the standard surface parameterization is given by these equations, where u and v are both defined on the interval [0, 1):
Figure 11 The standard surface parameterization for an ellipsoid.
Some objects have neither a natural surface parameterization nor a standard surface parameterization supplied by QuickDraw 3D. For example, the faces of a mesh have neither type of parameterization. To apply a texture to such an object, you need to define your own custom surface parameterization. You do this by adding attributes of type kQ3AttributeTypeSurfaceUV to the vertices of the object. See Listing 9 for details.
It's possible to modify the mapping used in applying a texture to a surface, by changing the surface's uv shading transform. (For example, you can rotate the texture any desired amount by installing the appropriate transformation matrix.) See the chapter "Shader Objects" for information on setting the uv transform used by a surface shader.
To override an object's standard surface parameterization, or to define a custom surface parameterization for an object that has no standard surface parameterization, you need to manipulate the surface uv attributes of the object. See the chapter "Attribute Objects" for details.
The standard surface parameterizations of the QuickDraw 3D geometric objects are given in the section "Geometric Objects Reference."
Previous | QD3D Book | Overview | Chapter Contents | Next |